package scene.composants.elements;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.io.Serializable;


/**
 * Objet Graphique PointExtremite
 * Dessin d'un carre bleu suivant un point representant son centre
 * Represente la selection d'un composant
 * 
 * @author Delmas Gabriel
 */
public class PointExtremite implements Serializable
{
	private static final long serialVersionUID = -4611503490285403279L;
	private Point p;
	private Rectangle contour;
	
	private boolean selection;

	
	public PointExtremite(int px,int py)
	{
		p = new Point(px,py);
		contour = new Rectangle(p.x-4, p.y-4, 8, 8);
		selection=false;
	}

	
	public void setSelection(boolean selection){this.selection=selection;}
	public boolean getSelection(){return this.selection;}
	
	public Point getPosition(){return p;}
	public void setPosition(Point p)
	{
		this.p=p;
		contour = new Rectangle(this.p.x-4, this.p.y-4, 8, 8);
	}
	
	public Rectangle getRectangle(){return contour;}
	
	
	public void dessiner(Graphics2D g2d)
	{
		Color couleur=g2d.getColor();
		if(selection)
		{
			g2d.setColor(Color.blue);
			g2d.drawRect(contour.x-2, contour.y-2, contour.width+3, contour.height+3);
			g2d.fillRect(contour.x, contour.y, contour.width, contour.height);
		}
		else
		{
			g2d.setColor(Color.blue);
			g2d.fillRect(contour.x, contour.y, contour.width, contour.height);
		}
		g2d.setColor(couleur);
	}
	
	public boolean Clique(Point p)
	{
		return contour.contains(p);
	}
}
